package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class NuevoPiloto extends javax.swing.JFrame {
    
    javax.sound.sampled.Clip sonido;
    boolean verificacion = false;
    File file;
    ButtonGroup bc;
    String eleccion;
    String nom,ape;
    static String foto;
    Limitador limeda = new Limitador(2);
    Limitador limtel = new Limitador(8);
    Limitador limin = new Limitador(2);
    Limitador limcel = new Limitador(13);
    Limitador limi = new Limitador(20);
    Limitador limcd = new Limitador(11);
    Limitador limdir = new Limitador(50);
    Limitador limcesp = new Limitador(50);
    Limitador limnom = new Limitador(30);
    Limitador limcap = new Limitador(50);
    CamaraWeb cam;
    Ventana ven;
    Ventana va;
    String fot;
    public NuevoPiloto() {
        initComponents();
        bc = new ButtonGroup();
        bc.add(camion);
        bc.add(cabezal);
        ceda.setDocument(limeda);      
        ctel.setDocument(limtel);
        cfam.setDocument(limin);
        clic.setDocument(limcel);
        cced.setDocument(limi);
        cd.setDocument(limcd);
        cdir.setDocument(limdir);
        cesp.setDocument(limcesp);
        cnom.setDocument(limnom);
        cape.setDocument(limcap);
  }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ceda = new javax.swing.JTextField();
        cfoto = new javax.swing.JTextField();
        cd = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        clic = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        prefoto = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        camion = new javax.swing.JRadioButton();
        cabezal = new javax.swing.JRadioButton();
        jButton4 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        cced = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        ctel = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        cfam = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cesp = new javax.swing.JTextField();
        cnom = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cape = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        cdir = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setFocusTraversalPolicyProvider(true);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                formKeyReleased(evt);
            }
        });

        ceda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cedaActionPerformed(evt);
            }
        });
        ceda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cedaKeyTyped(evt);
            }
        });

        cd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdActionPerformed(evt);
            }
        });
        cd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cdKeyTyped(evt);
            }
        });

        jLabel7.setText("Foto");
        jLabel7.setFocusable(false);

        jLabel1.setText("C o d i g o ");
        jLabel1.setFocusable(false);

        clic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicActionPerformed(evt);
            }
        });

        jLabel3.setText("Licencia");
        jLabel3.setFocusable(false);

        jLabel2.setText("Nombre");
        jLabel2.setFocusable(false);

        jLabel5.setText("Tipo Piloto");
        jLabel5.setFocusable(false);

        jLabel4.setText("Edad");
        jLabel4.setFocusable(false);

        prefoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Pilotos.gif"))); // NOI18N
        prefoto.setFocusable(false);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        jButton3.setText("Cancerlar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        jButton1.setText("Ingresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        camion.setSelected(true);
        camion.setText("Camion ");
        camion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                camionActionPerformed(evt);
            }
        });

        cabezal.setText("Cabezal ");
        cabezal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cabezalActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316233577_folder_search.png"))); // NOI18N
        jButton4.setText("Cargar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel6.setText("Cedula ");
        jLabel6.setFocusable(false);

        cced.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccedActionPerformed(evt);
            }
        });

        jLabel8.setText("Telefono ");
        jLabel8.setFocusable(false);

        ctel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ctelActionPerformed(evt);
            }
        });
        ctel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ctelKeyTyped(evt);
            }
        });

        jLabel9.setText("Dirección");
        jLabel9.setFocusable(false);

        jLabel11.setText("Integrantes en Familia ");
        jLabel11.setFocusable(false);

        cfam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfamActionPerformed(evt);
            }
        });
        cfam.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cfamKeyTyped(evt);
            }
        });

        jLabel12.setText("Nombre Esposa ");
        jLabel12.setFocusable(false);

        cesp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cespActionPerformed(evt);
            }
        });
        cesp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cespKeyTyped(evt);
            }
        });

        cnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnomActionPerformed(evt);
            }
        });
        cnom.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cnomKeyTyped(evt);
            }
        });

        jLabel10.setText("Apellido ");
        jLabel10.setFocusable(false);

        cape.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                capeKeyTyped(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316233129_Camera.png"))); // NOI18N
        jButton2.setText("Tomar Foto");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        cdir.setColumns(20);
        cdir.setLineWrap(true);
        cdir.setRows(7);
        jScrollPane1.setViewportView(cdir);

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));
        jPanel1.setFocusable(false);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Nuevo Piloto ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(264, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(9, 9, 9)
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(77, 77, 77)
                                .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(74, 74, 74)
                                .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(77, 77, 77)
                                .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(78, 78, 78)
                                .addComponent(cced, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(69, 69, 69)
                                .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(37, 37, 37)
                                .addComponent(cesp, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(90, 90, 90)
                                .addComponent(ceda, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel7))
                                    .addComponent(prefoto, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton2)
                                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cfoto, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5)
                                .addGap(53, 53, 53)
                                .addComponent(camion)
                                .addGap(93, 93, 93)
                                .addComponent(cabezal))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel9))
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cfam, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton3)))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3, jButton4});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel2))
                    .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel10))
                    .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel3))
                    .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel6))
                    .addComponent(cced, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel8))
                    .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel9))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel11))
                    .addComponent(cfam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel12))
                    .addComponent(cesp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(ceda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel5))
                    .addComponent(camion)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(cabezal)))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel7))
                    .addComponent(cfoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(prefoto)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addGap(11, 11, 11)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3, jButton4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cedaActionPerformed
}//GEN-LAST:event_cedaActionPerformed

    private void cdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdActionPerformed
}//GEN-LAST:event_cdActionPerformed

    private void clicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicActionPerformed
}//GEN-LAST:event_clicActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        dispose();
        Piloto va;

        va = new Piloto();
        va.setVisible(true);
        va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width - 114, Toolkit.getDefaultToolkit().getScreenSize().height - 107);

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            cd.setBackground(Color.darkGray);
            cced.setBackground(Color.darkGray);
            cd.setBackground(Color.darkGray);
            cdir.setBackground(Color.darkGray);
            cesp.setBackground(Color.darkGray);
            cfam.setBackground(Color.darkGray);
            cfoto.setBackground(Color.darkGray);
            clic.setBackground(Color.darkGray);
            ceda.setBackground(Color.darkGray);
            cnom.setBackground(Color.darkGray);
            ctel.setBackground(Color.darkGray);
            cape.setBackground(Color.darkGray);
            Insertar();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NuevoPiloto.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (verificacion == true) {
            dispose();
            Piloto va;

            va = new Piloto();
            va.setVisible(true);
            // centramos la pantalla
            va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width - 114, Toolkit.getDefaultToolkit().getScreenSize().height - 107);

        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
boolean vista = false;
foto = cam.direc;
if(foto==null){
            FileDialog filAbrir = new FileDialog(this, "Abrir archivo", FileDialog.LOAD);
            filAbrir.show();
                cfoto.setText(""+filAbrir.getDirectory()+filAbrir.getFile());
                vista = true;
}
else{
    foto=CamaraWeb.direc;//toma la dirección de la fotografía
        cfoto.setText(foto);//la ingresa a la caja de dirección de la fotografía
        cam.direc=null;
        vista = true;
}
        // generare un preview
if(vista)      
preview();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void ccedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccedActionPerformed
    }//GEN-LAST:event_ccedActionPerformed

    private void ctelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctelActionPerformed
    }//GEN-LAST:event_ctelActionPerformed

    private void cfamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfamActionPerformed
    }//GEN-LAST:event_cfamActionPerformed

    private void cespActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cespActionPerformed
    }//GEN-LAST:event_cespActionPerformed

    private void cnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnomActionPerformed
    }//GEN-LAST:event_cnomActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       va = new Ventana(nom, ape);
        ven = new Ventana();
        ven.setVisible(true);
        ven.setBounds(this.getSize().width, 0, 323, 300);
        
}//GEN-LAST:event_jButton2ActionPerformed

    private void camionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_camionActionPerformed

    private void cabezalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cabezalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cabezalActionPerformed
  
   
   
    private void cfamKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cfamKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_cfamKeyTyped

    private void cedaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cedaKeyTyped
           char c = evt.getKeyChar();
          
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
       
    }//GEN-LAST:event_cedaKeyTyped

    private void cdKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cdKeyTyped
          char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_cdKeyTyped

    private void cnomKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cnomKeyTyped
        char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cnomKeyTyped

    private void capeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_capeKeyTyped
       char c = evt.getKeyChar();
       if(!(Character.isLetter(c)|| (c== KeyEvent.VK_BACK_SPACE) || (c==evt.VK_DELETE) || ((c== KeyEvent.VK_SPACE))))
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_capeKeyTyped

    private void cespKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cespKeyTyped
           char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cespKeyTyped

    private void ctelKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ctelKeyTyped

        char c = evt.getKeyChar();
        if (!(Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
        {
            getToolkit().beep();
            evt.consume();
        }

    }//GEN-LAST:event_ctelKeyTyped

    private void formKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyReleased
    
     
    }//GEN-LAST:event_formKeyReleased

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
           
    }//GEN-LAST:event_formKeyPressed
// metodo preview sirve para que el usuario se asegure qee es la imagen la qee selecciono . ;D


    public void preview() {

        ImageIcon im = new ImageIcon(cfoto.getText());
        // creare una condicion cuando la imagen sea demasiado grande

        if (im.getIconWidth() > 105 || im.getIconHeight() > 118) {
            ImageIcon imaescala = new ImageIcon(im.getImage().getScaledInstance(105, 118, 100));
            prefoto.setIcon(imaescala);
        } else {
            prefoto.setIcon(im);
        }



    }
    public void Insertar() throws FileNotFoundException {
        try {
            int resultado = 0;
// codio para conectarme 
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            // coneccion
            Connection conexion = (Connection) dataSource.getConnection();

            PreparedStatement ps = null;
            ps = (PreparedStatement) conexion.prepareStatement("insert into piloto (idpiloto,nombre,apellido, licencia,cedula,telefono,direccion,nomesposa,numintegrantes,"
                    + "edad,tipopiloto,foto) values (?,?,?,?,?,?,?,?,?,?,?,?)");


            try {

                ps.setInt(1, Integer.parseInt(cd.getText()));

            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Error en el dato de Numero economico de Piloto. \n Dato no Ingresado o Dato Repetido. ");
                cd.setBackground(Color.red);
                cd.setText("" + "Error");
            }
            try {

                if (cnom.getText() == null ? "" == null : cnom.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos Nombre");
                    cnom.setBackground(Color.red);
                    cnom.setText("" + "Error");

                } else {
                    ps.setString(2, cnom.getText()); // con el ps genero lo qee voy a ingresar
                    //lo genero en orden el 1 va a ser el dato uno en este caso seria nombre
                    // y como nombre es varchar tonces sera string
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                cnom.setBackground(Color.red);
                cnom.setText("" + "Error");
            }
            //apellido
            try {
                if (cape.getText() == null ? "" == null : cape.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Apellido");
                    cape.setBackground(Color.red);
                    cape.setText("" + "Error");

                } else {
                    ps.setString(3, cape.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                cape.setBackground(Color.red);
                cape.setText("" + "Error");
            }

            // licencia
            try {
                if (clic.getText() == null ? "" == null : clic.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Licencia");
                    clic.setBackground(Color.red);
                    clic.setText("" + "Error");

                } else {
                    ps.setString(4, clic.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                clic.setBackground(Color.red);
                clic.setText("" + "Error");
            }


// cedula

            try {
                if (cced.getText() == null ? "" == null : cced.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en cedula");
                    cced.setBackground(Color.red);
                    cced.setText("" + "Error");

                } else {
                    ps.setString(5, cced.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                cced.setBackground(Color.red);
                cced.setText("" + "Error");
            }

// telefono
            try {
               if (ctel.getText() == null ? "" == null : ctel.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Licencia");
                    ctel.setBackground(Color.red);
                    ctel.setText("" + "Error");

                } else {
                    ps.setString(6, ctel.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                ctel.setBackground(Color.red);
                ctel.setText("" + "Error");
            }
//direccion
            try {
                if (cdir.getText() == null ? "" == null : cdir.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en dirección ");
                    cdir.setBackground(Color.red);
                    cdir.setText("" + "Error");

                } else {
                    ps.setString(7, cdir.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                cdir.setBackground(Color.red);
                cdir.setText("" + "Error");
            }

//nombre de la esposa
            try {
                if (cesp.getText() == null ? "" == null : cesp.getText().equals("")) {

                    JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Nombre Esposa");
                    cesp.setBackground(Color.red);
                    cesp.setText("" + "Error");

                } else {
                    ps.setString(8, cesp.getText());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
                cesp.setBackground(Color.red);
                cesp.setText("" + "Error");
            }

//numero de integrantes en la familia
            try {
                if (Integer.parseInt(cfam.getText()) >= 10) {
                    JOptionPane.showMessageDialog(this, "Dato Erroneo en Integrantes Familia, demaciados integrantes");
                    cfam.setBackground(Color.red);
                    cfam.setText("" + "Error");
                }
                ps.setInt(9, Integer.parseInt(cfam.getText()));
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Dato Erroneo en Integrantes Familia, debe utilizar solo numeros");
                cfam.setBackground(Color.red);
                cfam.setText("" + "Error");
            }
            //edad
            try {



                if (Integer.parseInt(ceda.getText()) <= 17) {
                    JOptionPane.showMessageDialog(this, "Dato Errone en Edad, debe ser mayor a 17 años");
                    ceda.setBackground(Color.red);
                    ceda.setText("" + "Error");

                }

                ps.setInt(10, Integer.parseInt(ceda.getText()));

            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato no ingresado error en el dato edad" + resultado);
                ceda.setBackground(Color.red);
                ceda.setText("" + "Error");
            }
            //Tipo Piloto
            try {
                if (camion.isSelected()) {
                    eleccion = "Camion";

                } else {
                    eleccion = "Cabezal";
                }

                ps.setString(11, (eleccion));


            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato no ingresado  Revisar Manual" + resultado);

            }

            //Foto
            if (cfoto.getText() != null) {
                file = new File(cfoto.getText()); // el file nuevo
                // sera el que acabavos de abrir
            } else {
                file = new File(System.getProperty("user.dir") + "\\src\\Imagenes\\Pilotos.gif");
            }
            // prepara para meter los datos
            FileInputStream fis = null;

            try {
                fis = new FileInputStream(file);
            } catch (FileNotFoundException ex) {
            }

            ps.setBinaryStream(12, fis, (int) file.length());


            resultado = ps.executeUpdate();
            // sonido


            try {
                sonido = null;
                sonido = AudioSystem.getClip();
                sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty("user.dir") + "\\src\\SonidosPractica\\Correcto2.wav")));
                sonido.start();




            } catch (Exception e) {
                System.out.println("" + e);
            } // fin

            JOptionPane.showMessageDialog(rootPane, "Dato ingresado exitosamente" + resultado);
            verificacion = true;

            conexion.close(); // cierro la conexion

        } catch (SQLException e) {

            JOptionPane.showMessageDialog(rootPane, e);

            /*verificacion=false;
            cd.setBackground(Color.red);
            
            cd.setText(""+"Error");*/
        } // fin del catch
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NuevoPiloto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton cabezal;
    private javax.swing.JRadioButton camion;
    private javax.swing.JTextField cape;
    private javax.swing.JTextField cced;
    private javax.swing.JTextField cd;
    private javax.swing.JTextArea cdir;
    private javax.swing.JTextField ceda;
    private javax.swing.JTextField cesp;
    private javax.swing.JTextField cfam;
    public javax.swing.JTextField cfoto;
    private javax.swing.JTextField clic;
    private javax.swing.JTextField cnom;
    private javax.swing.JTextField ctel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JLabel prefoto;
    // End of variables declaration//GEN-END:variables
}
